<!DOCTYPE html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<style>
.overflow {
  counter-reset: c 0;
}

.overflow h3:before {
  counter-increment: c 500000000;
}

.underflow {
  counter-reset: c 0;
}

.underflow h3:before {
  counter-increment: c -500000000;
}

h3::before {
  content: counter(c);
}
</style>
<div id="headings">
</div>
<script>
var headings = document.getElementById('headings');
var items = [];

for (var i = 0; i < 5; i++) {
  items.push(document.createElement('h3'));
  headings.appendChild(items[i]);
}

function get_list_counters() {
  var counters = [];
  for (var i = 0; i < items.length; i++) {
    counters.push(parseInt(internals.counterValue(items[i])));
  }
  return counters;
}

/* The spec [1] allows implementation-specific limits on the value of counters.
   The only requirement is that "If an increment would push the counter’s value
   beyond these limits, the increment must be ignored, and the counter’s value
   remain unchanged."

   We assume a 32 bit int limit.
*/
test(function() {
  headings.className = 'overflow';
  assert_array_equals(get_list_counters(),
    [500000000, 1000000000, 1500000000, 2000000000, 2000000000]);
}, 'large reset does not overflow');

test(function() {
  headings.className = 'underflow';
  assert_array_equals(get_list_counters(),
    [-500000000, -1000000000, -1500000000, -2000000000, -2000000000]);
}, 'small reset does not underflow');

</script>
